$(function() {
	var arr = [
		'./img/banner/banner1.jpg',
		'./img/banner/banner2.jpg',
		'./img/banner/banner3.jpg',
		'./img/banner/banner4.jpg',
		'./img/banner/banner5.jpg',
		'./img/banner/banner6.jpg'
	];
	
	//获取屏幕尺寸
	var winWidth;
	var mWidth;
	var mHeight;
	if(window.innerWidth){
		winWidth=window.innerWidth;
	}else if((document.body)&&(document.body.clientWidth)){
		winWidth=document.body.clientWidth;
	}
	
	//设置窗口宽度
	//保持宽高比
	function setWinWidth(){
		//设置scon的width占比
		main=document.getElementById('scon');
		mWidth = winWidth * (90/100);
		console.log(mWidth);
		main.style.width=mWidth+"px";
		//设置mian的height占比
		mHeight = mWidth*(280/520);
		main.style.height=mHeight+"px";
	}
	//获取页面宽度
	setWinWidth();
	creatImg(arr);
	//设置css属性
	$('.imgCon').css({
		left: 0,
		width:mWidth,
		height:mHeight
	})
	
	// 默认第一张,创建img标签节点
	function creatImg(arr){
		$.each(arr, function(i, m) {
			var gg = document.createElement('img');
			$(gg).attr('src', m);
			//console.log(mWidth);
			//console.log(gg);
			gg.setAttribute('width',mWidth+"px");
			gg.setAttribute('height',mHeight+"px");
			$('.imgCon').append(gg);
		});
	}
	
	
	
	var derection = true;
	

	function time() {
		if (derection) { //向左
			$('.imgCon').stop().animate({
				left: -mWidth
			}, function() {
				$('.imgCon').css({
					left: 0
				});
				var i = arr.shift();
				arr.push(i);
				$('.imgCon').html('');
				creatImg(arr);
			})
		} else {//向右边
			$('.imgCon').css({
				left:-mWidth
			});
			var i = arr.pop();
			arr.unshift(i);
			$('.imgCon').html('');
			creatImg(arr);
			
			$('.imgCon').stop().animate({
				left: 0
			}, function() {

			})
		}

	}

	var timer = setInterval(time, 3000);
	$('.container').mouseover(function() {
		clearInterval(timer);
	});
	$('.container').mouseleave(function() {
		timer = setInterval(time, 3000);
		derection = true;
	});
	$('#next').click(function() {
		derection = false;
		time();
	});
	$('#prev').click(function() {
		derection = true;
		time();
	});
})
